package com.cyf.third.kuting.service;

import com.cyf.third.kuting.network.bean.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * 第三方酷停接口
 * Created by cage on 2017/2/6.
 */
@Controller
@RestController
@RequestMapping(value = "/third/kuting")
@Api("第三方酷停相关api")
public class KTHttpController {

    @Autowired
    KTService ktService;

    @ApiOperation(value = "用户在酷停服务器完成预定后请求接口，云端将预定的信息通知车场")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "platenum", value = "车牌号", required = true, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "parkingid", value = "车场id", required = true, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "startTime", value = "车位预定时间", required = true, dataType = "Date", paramType = "query"),
            @ApiImplicitParam(name = "endTime", value = "车辆最迟入场时间", required = true, dataType = "Date", paramType = "query")
    })
    @RequestMapping(value = "/creOrderNotice", method = RequestMethod.GET)
    public CreOrderNoticeRsp creOrderNotice(@RequestParam(value = "platenum") String plateNum,
                               @RequestParam(value = "parkingid") Integer parkingId,
                               @RequestParam(value = "startTime") String startTime,
                               @RequestParam(value = "endTime") String endTime) {
        CreOrderNoticeReq req = new CreOrderNoticeReq();
        req.setPlateNum(plateNum);
        req.setParkingId(parkingId);
        req.setStartTime(startTime);
        req.setEndTime(endTime);
        return ktService.creOrderNotice(req);
    }

    @ApiOperation(value = "用户在酷停服务器取消订单后请求接口，云端将车位取消信息通知车场")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "platenum", value = "车牌号", required = true, dataType = "String", paramType = "query"),
            //@ApiImplicitParam(name = "parkingname", value = "车场名称", required = true, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "parkingid", value = "车场id", required = true, dataType = "int", paramType = "query")
    })
    @RequestMapping(value = "/delOrderNotice", method = RequestMethod.GET)
    public DelOrderNoticeRsp delOrderNotice(
            @RequestParam(value = "platenum") String plateNum,
            // @RequestParam(value = "parkingname") String parkingName
            @RequestParam(value = "parkingid") Integer parkingId) {
        DelOrderNoticeReq req = new DelOrderNoticeReq();
        req.setPlateNum(plateNum);
//        req.setParkingName(parkingName);
        req.setParkingId(parkingId);
        return ktService.delOrderNotice(req);
    }

    @ApiOperation(value = "酷停平台请求停车费用")
    @ApiImplicitParams({
//            @ApiImplicitParam(name = "opt", value = "操作码", required = false, dataType = "integer", paramType = "query"),
            @ApiImplicitParam(name = "platenum", value = "车牌号", required = true, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "parkingid", value = "车场id", required = true, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "lefttime", value = "离场时间", required = true, dataType = "String", paramType = "query")
    })
    @RequestMapping(value = "/getFee", method = RequestMethod.GET)
    public GetFeeRsp getFee(
            // @RequestParam(value = "opt", required = false) Integer opt,
            @RequestParam(value = "platenum") String plateNum,
            @RequestParam(value = "parkingid") Integer parkingId,
            @RequestParam(value = "lefttime") String lefttime) {
        GetFeeReq req = new GetFeeReq();
        req.setPlateNum(plateNum);
        req.setParkingId(parkingId);
        req.setLefttime(lefttime);
        return ktService.getFee(req);
    }

    @ApiOperation(value = "酷停平台上报停车费用")
    @ApiImplicitParams({
//            @ApiImplicitParam(name = "opt", value = "操作码", required = false, dataType = "integer", paramType = "query"),
            @ApiImplicitParam(name = "platenum", value = "车牌号", required = true, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "parkingid", value = "车场id", required = true, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "deadline", value = "离场时间", required = true, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "fee", value = "费用(分)", required = true, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "orderid", value = "订单号", required = true, dataType = "String", paramType = "query")
    })
    @RequestMapping(value = "/uploadFee", method = RequestMethod.GET)
    public UploadFeeRsp uploadFee(@RequestParam(value = "platenum") String plateNum,
                                  @RequestParam(value = "parkingid") Integer parkingId,
                                  @RequestParam(value = "deadline") String deadline,
                                  @RequestParam(value = "fee") Integer fee,
                                  @RequestParam(value = "orderid") String orderId){
        UploadFeeReq req = new UploadFeeReq();
        req.setPlateNum(plateNum);
        req.setParkingId(parkingId);
        req.setDeadline(deadline);
        req.setFee(fee);
        req.setOrderid(orderId);
        return ktService.uploadFee(req);
    }

    @ApiOperation(value = "获取车场列表")
    @RequestMapping(value = "/getParkingList", method = RequestMethod.GET)
    public ParkingList getParkingList() {
        return ktService.getParkingList();
    }
}
